#include <iostream>
using std::cout;
using std::endl;


template <class T>
class RAII
{
public:
    RAII(T * data)
    : _data(data)
    {
        cout << "RAII(T*)" << endl;
    }

    ~RAII(){
        cout << "~RAII()" << endl;
        if(_data){
            delete _data;
            _data = nullptr;
        }
    }

    T * operator->(){
        return _data;
    }

    T & operator*(){
        return *_data;
    }

    T * get() const{
        return _data;
    }

    void set(T * data){
        if(_data){
            delete _data;
            _data = nullptr;
        }
        _data = data;
    }

    RAII(const RAII &) = delete;
    RAII& operator=(const RAII &) = delete;
private:
    T * _data;
};

void test0(){
    int * p = new int(10);
    cout << p << endl;

    RAII<int> ra(p);
    cout << *ra << endl;
    cout << ra.get() << endl;
    /* delete p; */
}

void test1(){
    RAII<int> ra(new int(20));
    cout << *ra << endl;
    cout << ra.get() << endl;
}



int main(void){
    test1();
    return 0;
}
